<template>
	<view class="page">
		<view class="form-content">
			<u-form :model="formData" ref="uForm" class="uForm" label-position="top">
				<u-form-item prop="majorRelationPerson" label="重大关系人姓名" label-width="auto">
					<u-input v-model="formData.majorRelationPerson" placeholder="请输入重大关系人姓名" />
				</u-form-item>
				<u-form-item prop="loanFinancialInstitutionsCount" label="贷款金融机构数" label-width="auto">
					<u-input v-model="formData.loanFinancialInstitutionsCount" placeholder="请输入贷款金融机构数" type="number" />
					<view slot="right">家</view>
				</u-form-item>
				<u-form-item prop="creditCardFinancialInstitutionsCount" label="信用卡金融机构数" label-width="auto">
					<u-input v-model="formData.creditCardFinancialInstitutionsCount" placeholder="请输入信用卡金融机构数"
						type="number" />
					<view slot="right">家</view>
				</u-form-item>
				<u-form-item prop="creditCardTotal" label="信用卡总额" label-width="auto">
					<u-input v-model="formData.creditCardTotal" placeholder="请输入信用卡总额" type="digit" />
					<view slot="right">元</view>
				</u-form-item>
				<u-form-item prop="creditCardUsageAmount" label="信用卡使用额" label-width="auto">
					<u-input v-model="formData.creditCardUsageAmount" placeholder="请输入信用卡使用额" type="digit" />
					<view slot="right">元</view>
				</u-form-item>
				<u-form-item prop="loanInquiryCountInHalfYear" label="半年内贷款审批查询次数" label-width="auto">
					<u-input v-model="formData.loanInquiryCountInHalfYear" placeholder="请输入次数" type="number" />
					<view slot="right">次</view>
				</u-form-item>
				<u-form-item prop="creditCardInquiryCountInHalfYear" label="半年内信用卡审批查询次数" label-width="auto">
					<u-input v-model="formData.creditCardInquiryCountInHalfYear" placeholder="请输入次数" type="number" />
					<view slot="right">次</view>
				</u-form-item>
				<u-form-item prop="overdueCountInTwoYears" label="两年内逾期次数" label-width="auto">
					<u-input v-model="formData.overdueCountInTwoYears" placeholder="请输入两年内逾期次数" type="number" />
					<view slot="right">次</view>
				</u-form-item>
				<u-form-item prop="overdueCountInFiveYears" label="五年内逾期次数" label-width="auto">
					<u-input v-model="formData.overdueCountInFiveYears" placeholder="请输入五年内逾期次数" type="number" />
					<view slot="right">次</view>
				</u-form-item>
				<u-form-item prop="m2AndAboveInformation" label="M2及以上的信息" label-width="auto" label-position="top">
					<u-input v-model="formData.m2AndAboveInformation" placeholder="请输入M2及以上的信息" type="textarea" />
				</u-form-item>
				<u-form-item prop="attachment" label="附件信息" label-width="auto" label-position="top">
					<JNPFUpload v-model="attendanceFileList" :fileSize='2' :limit='10' :showLabel="false"
						@uploading="uploading">
					</JNPFUpload>
				</u-form-item>
			</u-form>
		</view>
		<view class="save-bottom">
			<view class="fixed-btn save-padding">
				<u-button type="primary" shape="circle" :disabled="btnDisabled" @click="onSubmit">确定</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	const apiUrl = "/api/Jiushi/Customermajorcredit";
	export default {
		components: {},
		name: 'Customermajorcredit',
		data() {
			return {
				formData: {
					id: undefined,
					customerId: undefined,
					majorRelationPerson: undefined,
					loanFinancialInstitutionsCount: undefined,
					creditCardFinancialInstitutionsCount: undefined,
					creditCardTotal: undefined,
					creditCardUsageAmount: undefined,
					loanInquiryCountInHalfYear: undefined,
					creditCardInquiryCountInHalfYear: undefined,
					overdueCountInTwoYears: undefined,
					overdueCountInFiveYears: undefined,
					m2AndAboveInformation: undefined,
					attachment: undefined,
				},
				attendanceFileList: [],
				isMortgaged: false,
				btnDisabled: false
			}
		},
		onLoad(options) {
			if (options.cid) {
				this.formData.customerId = options.cid
			}
			if (options.id) {
				this.formData.id = options.id
				this.init()
			}
		},
		methods: {
			uploading(flag) {
				this.btnDisabled = flag
			},
			/* 初始化请求 */
			init() {
				this.$helper.ajax({
					url: apiUrl + "/" + this.formData.id,
					method: "GET",
					contentType: "application/json",
					success: res => {
						this.formData = res.data.data
						if (this.formData.attachment) {
							this.attendanceFileList = res.data.data.attachment.split(',').map(item => {
								let tempItem = {
									url: item
								}
								return tempItem
							})
						}
					}
				});
			},
			change(e) {
				console.log('change', e);
				this.formData.isMortgaged = e ? 1 : 0
			},
			/* 表单提交 */
			onSubmit() {
				this.formData.attachment = this.attendanceFileList.map(item => {
					return item.url
				}).join(',')
				let url = apiUrl;
				let method = "POST";
				if (this.formData.id) {
					url = url + "/" + this.formData.id;
					method = "PUT";
				}
				this.$helper.ajax({
					url: url,
					method: method,
					contentType: "application/json",
					data: this.formData,
					success: res => {
						this.$helper.msg('保存成功', 'success');
						uni.setStorage({
							key: "refreshPage",
							data: true
						})
						uni.navigateBack();
					}
				});
			},
		}
	}
</script>

<style>

</style>